﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExternalConnections.CUiSimulationSettingsForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.ExternalConnections.Res;
using EngineeringInternalExtension;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using UiInternalControls;


namespace DnProcessSimulateCommands.ExternalConnections;

public class CUiSimulationSettingsForm : TxForm
{
  private CApECExternalConnectionDataEditConvertor m_convertor;
  private CApECExternalConnectionDataEditConvertor m_winModconvertor;
  private ToolTip m_toolTip;
  private ToolTip m_toolTipSimUnitPath;
  private ToolTip m_toolTipWinMod;
  private IContainer components;
  private GroupBox m_simulationSettingsGroupBox;
  private Label m_labelOperatingMode;
  private RadioButton m_radioButtonTimeSpanSyncOpMode;
  private RadioButton m_radioButtonDefaultOpMode;
  private RadioButton m_radioButtonSingleStep;
  private Button m_buttonCancel;
  private Button m_buttonOk;
  private TxInfoButton m_pictureBox;
  private Label m_lableCycleTime;
  private TxNumericEditBoxCtrl m_cycleTimeOut;
  private Label m_lableMsUnit;
  private GroupBox groupBox1;
  private TxInfoButton m_pictureBoxSimUnit;
  private Button m_buttonBrowseSimUnitPath;
  private TextBox m_textBoxSimUnitPath;
  private Label m_labelSimUnitPath;
  private GroupBox m_winModgroupBox;
  private Label m_lableWinModMsUnit;
  private TxNumericEditBoxCtrl m_winMod_TimeOut;
  private Label m_timeOutLable;
  private TxInfoButton m_WinModpictureBox;

  public CUiSimulationSettingsForm()
  {
    this.InitializeComponent();
    this.LoadregistryKeyValues();
    this.LoadSimulationUnitPath();
    this.LoadwinModregistryKeyValues();
    this.m_toolTip = new ToolTip();
    this.m_toolTip.SetToolTip((Control) this.m_pictureBox, CUiECExternalConnectionsResourceTable.SIMULATION_SETTINGS_INFO);
    this.m_toolTip.AutoPopDelay = 30000;
    this.m_toolTip.InitialDelay = 500;
    this.m_toolTip.ReshowDelay = 150;
    this.m_toolTip.ShowAlways = true;
    this.m_pictureBox.TooltipText = CUiECExternalConnectionsResourceTable.SIMULATION_SETTINGS_INFO;
    this.m_toolTipSimUnitPath = new ToolTip();
    this.m_toolTipSimUnitPath.SetToolTip((Control) this.m_pictureBoxSimUnit, CUiECExternalConnectionsResourceTable.SIMULATION_UNIT_PATH_INFO);
    this.m_toolTipSimUnitPath.AutoPopDelay = 30000;
    this.m_toolTipSimUnitPath.InitialDelay = 500;
    this.m_toolTipSimUnitPath.ReshowDelay = 150;
    this.m_toolTipSimUnitPath.ShowAlways = true;
    this.m_pictureBoxSimUnit.TooltipText = CUiECExternalConnectionsResourceTable.SIMULATION_UNIT_PATH_INFO;
    this.m_toolTipWinMod = new ToolTip();
    this.m_toolTipWinMod.SetToolTip((Control) this.m_WinModpictureBox, CUiECExternalConnectionsResourceTable.WIN_MOD_INFO);
    this.m_toolTipWinMod.AutoPopDelay = 30000;
    this.m_toolTipWinMod.InitialDelay = 500;
    this.m_toolTipWinMod.ReshowDelay = 150;
    this.m_toolTipWinMod.ShowAlways = true;
    this.m_WinModpictureBox.TooltipText = CUiECExternalConnectionsResourceTable.WIN_MOD_INFO;
    ((Control) this).MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width * 2, ((Control) this).Height);
    ((Control) this).MinimumSize = new Size(((Control) this).Width, ((Control) this).Height);
  }

  private void m_buttonOk_Click(object sender, EventArgs e)
  {
    int operatingMode = (int) this.m_convertor.OperatingMode;
    int num1 = -1;
    if (this.m_radioButtonDefaultOpMode.Checked)
      num1 = 0;
    else if (this.m_radioButtonTimeSpanSyncOpMode.Checked)
      num1 = 1;
    else if (this.m_radioButtonSingleStep.Checked)
      num1 = 2;
    if (operatingMode != num1 && !TxApplication.ActiveDocument.SimulationPlayer.IsSimulationReset())
    {
      int num2 = (int) TxMessageBox.ShowModal(CUiECExternalConnectionsResourceTable.RESET, CUiECExternalConnectionsResourceTable.PS, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
      TxApplication.ActiveDocument.SimulationPlayer.AskUserForReset(false);
      TxApplication.ActiveDocument.SimulationPlayer.Rewind();
    }
    ((Form) this).DialogResult = DialogResult.OK;
    if (((Form) this).Modal)
      return;
    ((Form) this).Close();
  }

  private void m_buttonCancel_Click(object sender, EventArgs e)
  {
    ((Form) this).DialogResult = DialogResult.Cancel;
    if (((Form) this).Modal)
      return;
    ((Form) this).Close();
  }

  private void CUiSimulationSettingsForm_FormClosing(object sender, FormClosingEventArgs e)
  {
    if (((Form) this).DialogResult == DialogResult.OK)
    {
      this.SaveRegistryKeyValues();
      this.SaveSimulationUnitPath();
      this.SaveWinModRegistryKeyValues();
    }
    this.OnClosing((CancelEventArgs) e);
  }

  private void m_radioButtonTimeSpanSyncOpMode_CheckedChanged(object sender, EventArgs e)
  {
    this.UpdateCycleTimeOutEnabler();
  }

  private void m_radioButtonDefaultOpMode_CheckedChanged(object sender, EventArgs e)
  {
    this.UpdateCycleTimeOutEnabler();
  }

  private void radioButtonSingleStep_CheckedChanged(object sender, EventArgs e)
  {
    this.UpdateCycleTimeOutEnabler();
  }

  private void m_buttonBrowseSimUnitPath_Click(object sender, EventArgs e)
  {
    using (TxFolderBrowserDialog folderBrowserDialog = new TxFolderBrowserDialog())
    {
      if (folderBrowserDialog.ShowDialog((Form) this) != 1)
        return;
      this.m_textBoxSimUnitPath.Text = folderBrowserDialog.SelectedFolder;
    }
  }

  public void SetOperatingMode(int operatingMode)
  {
    switch (operatingMode)
    {
      case 0:
        this.m_radioButtonDefaultOpMode.Checked = true;
        this.m_radioButtonTimeSpanSyncOpMode.Checked = false;
        this.m_radioButtonSingleStep.Checked = false;
        break;
      case 1:
        this.m_radioButtonDefaultOpMode.Checked = false;
        this.m_radioButtonTimeSpanSyncOpMode.Checked = false;
        this.m_radioButtonSingleStep.Checked = true;
        break;
      case 2:
        this.m_radioButtonDefaultOpMode.Checked = false;
        this.m_radioButtonTimeSpanSyncOpMode.Checked = true;
        this.m_radioButtonSingleStep.Checked = false;
        break;
    }
    this.UpdateCycleTimeOutEnabler();
    this.SaveRegistryKeyValues();
  }

  private void LoadregistryKeyValues()
  {
    this.m_convertor = (CApECExternalConnectionDataEditConvertor) new CApECExternalConnectionDataEditConvertor().CreateInstance((ITxPlcExternalConnectionDataEx) new TxPlcSimAdvConnectionDataEx());
    if ((int) this.m_convertor.OperatingMode == 0)
    {
      this.m_radioButtonDefaultOpMode.Checked = true;
      this.m_radioButtonTimeSpanSyncOpMode.Checked = false;
      this.m_radioButtonSingleStep.Checked = false;
    }
    else if ((int) this.m_convertor.OperatingMode == 1)
    {
      this.m_radioButtonDefaultOpMode.Checked = false;
      this.m_radioButtonTimeSpanSyncOpMode.Checked = true;
      this.m_radioButtonSingleStep.Checked = false;
    }
    else if ((int) this.m_convertor.OperatingMode == 2)
    {
      this.m_radioButtonDefaultOpMode.Checked = false;
      this.m_radioButtonTimeSpanSyncOpMode.Checked = false;
      this.m_radioButtonSingleStep.Checked = true;
    }
    this.m_cycleTimeOut.Value = (double) (int) this.m_convertor.CycleTimeOut;
    this.UpdateCycleTimeOutEnabler();
  }

  private void LoadwinModregistryKeyValues()
  {
    this.m_winModconvertor = (CApECExternalConnectionDataEditConvertor) new CApECExternalConnectionDataEditConvertor().CreateInstance((ITxPlcExternalConnectionDataEx) new TxPlcWinModConnectionDataEx());
    this.m_winMod_TimeOut.Value = (double) (int) this.m_winModconvertor.WinModTimeOut;
  }

  private void SaveRegistryKeyValues()
  {
    if (this.m_radioButtonDefaultOpMode.Checked)
      this.m_convertor.OperatingMode = (object) 0;
    else if (this.m_radioButtonTimeSpanSyncOpMode.Checked)
      this.m_convertor.OperatingMode = (object) 1;
    else if (this.m_radioButtonSingleStep.Checked)
      this.m_convertor.OperatingMode = (object) 2;
    this.m_convertor.CycleTimeOut = (object) (int) this.m_cycleTimeOut.Value;
  }

  private void SaveWinModRegistryKeyValues()
  {
    this.m_winModconvertor.WinModTimeOut = (object) (int) this.m_winMod_TimeOut.Value;
  }

  private void UpdateCycleTimeOutEnabler()
  {
    if (this.m_radioButtonTimeSpanSyncOpMode.Checked || this.m_radioButtonSingleStep.Checked)
    {
      this.m_cycleTimeOut.Enabled = true;
      this.m_lableCycleTime.Enabled = true;
      this.m_lableMsUnit.Enabled = true;
    }
    else
    {
      this.m_cycleTimeOut.Enabled = false;
      this.m_lableCycleTime.Enabled = false;
      this.m_lableMsUnit.Enabled = false;
    }
  }

  private void LoadSimulationUnitPath()
  {
    if (!TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded())
      return;
    TxPlcProgram currentPlcProgram = TxApplication.ActiveDocument.PlcProgramRoot.CurrentPlcProgram;
    if (TxPlcProgram.op_Equality(currentPlcProgram, (ITxObject) null))
      return;
    try
    {
      this.m_textBoxSimUnitPath.Text = new TxPlcProgramEx(currentPlcProgram).SimulationUnitProjectPath;
      this.m_buttonBrowseSimUnitPath.Enabled = true;
      this.m_textBoxSimUnitPath.ReadOnly = false;
    }
    catch (Exception ex)
    {
    }
  }

  private void SaveSimulationUnitPath()
  {
    if (!TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded())
      return;
    TxPlcProgram currentPlcProgram = TxApplication.ActiveDocument.PlcProgramRoot.CurrentPlcProgram;
    if (TxPlcProgram.op_Equality(currentPlcProgram, (ITxObject) null))
      return;
    try
    {
      new TxPlcProgramEx(currentPlcProgram).SimulationUnitProjectPath = this.m_textBoxSimUnitPath.Text;
    }
    catch (Exception ex)
    {
    }
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiSimulationSettingsForm));
    this.m_simulationSettingsGroupBox = new GroupBox();
    this.m_radioButtonSingleStep = new RadioButton();
    this.m_lableMsUnit = new Label();
    this.m_lableCycleTime = new Label();
    this.m_cycleTimeOut = new TxNumericEditBoxCtrl();
    this.m_pictureBox = new TxInfoButton();
    this.m_labelOperatingMode = new Label();
    this.m_radioButtonTimeSpanSyncOpMode = new RadioButton();
    this.m_radioButtonDefaultOpMode = new RadioButton();
    this.m_buttonCancel = new Button();
    this.m_buttonOk = new Button();
    this.groupBox1 = new GroupBox();
    this.m_pictureBoxSimUnit = new TxInfoButton();
    this.m_buttonBrowseSimUnitPath = new Button();
    this.m_textBoxSimUnitPath = new TextBox();
    this.m_labelSimUnitPath = new Label();
    this.m_winModgroupBox = new GroupBox();
    this.m_WinModpictureBox = new TxInfoButton();
    this.m_lableWinModMsUnit = new Label();
    this.m_winMod_TimeOut = new TxNumericEditBoxCtrl();
    this.m_timeOutLable = new Label();
    this.m_simulationSettingsGroupBox.SuspendLayout();
    this.groupBox1.SuspendLayout();
    this.m_winModgroupBox.SuspendLayout();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.m_simulationSettingsGroupBox, "m_simulationSettingsGroupBox");
    this.m_simulationSettingsGroupBox.Controls.Add((Control) this.m_radioButtonSingleStep);
    this.m_simulationSettingsGroupBox.Controls.Add((Control) this.m_lableMsUnit);
    this.m_simulationSettingsGroupBox.Controls.Add((Control) this.m_lableCycleTime);
    this.m_simulationSettingsGroupBox.Controls.Add((Control) this.m_cycleTimeOut);
    this.m_simulationSettingsGroupBox.Controls.Add((Control) this.m_pictureBox);
    this.m_simulationSettingsGroupBox.Controls.Add((Control) this.m_labelOperatingMode);
    this.m_simulationSettingsGroupBox.Controls.Add((Control) this.m_radioButtonTimeSpanSyncOpMode);
    this.m_simulationSettingsGroupBox.Controls.Add((Control) this.m_radioButtonDefaultOpMode);
    this.m_simulationSettingsGroupBox.Name = "m_simulationSettingsGroupBox";
    this.m_simulationSettingsGroupBox.TabStop = false;
    componentResourceManager.ApplyResources((object) this.m_radioButtonSingleStep, "m_radioButtonSingleStep");
    this.m_radioButtonSingleStep.Name = "m_radioButtonSingleStep";
    this.m_radioButtonSingleStep.UseVisualStyleBackColor = true;
    this.m_radioButtonSingleStep.CheckedChanged += new EventHandler(this.radioButtonSingleStep_CheckedChanged);
    componentResourceManager.ApplyResources((object) this.m_lableMsUnit, "m_lableMsUnit");
    this.m_lableMsUnit.Name = "m_lableMsUnit";
    componentResourceManager.ApplyResources((object) this.m_lableCycleTime, "m_lableCycleTime");
    this.m_lableCycleTime.Name = "m_lableCycleTime";
    this.m_cycleTimeOut.BorderStyle = BorderStyle.Fixed3D;
    componentResourceManager.ApplyResources((object) this.m_cycleTimeOut, "m_cycleTimeOut");
    this.m_cycleTimeOut.LowerBound = 1.0;
    ((Control) this.m_cycleTimeOut).Name = "m_cycleTimeOut";
    this.m_cycleTimeOut.ReadOnly = false;
    this.m_cycleTimeOut.StepSize = 1.0;
    this.m_cycleTimeOut.TextAlign = HorizontalAlignment.Left;
    this.m_cycleTimeOut.ThousandsSeparator = false;
    this.m_cycleTimeOut.UpperBound = 10000.0;
    this.m_cycleTimeOut.UseDecimalPlacesFromOption = true;
    this.m_cycleTimeOut.Value = 1.0;
    this.m_cycleTimeOut.ValueType = (TxNumericEditValueType) 3;
    componentResourceManager.ApplyResources((object) this.m_pictureBox, "m_pictureBox");
    ((Control) this.m_pictureBox).Name = "m_pictureBox";
    this.m_pictureBox.TabStop = false;
    componentResourceManager.ApplyResources((object) this.m_labelOperatingMode, "m_labelOperatingMode");
    this.m_labelOperatingMode.Name = "m_labelOperatingMode";
    componentResourceManager.ApplyResources((object) this.m_radioButtonTimeSpanSyncOpMode, "m_radioButtonTimeSpanSyncOpMode");
    this.m_radioButtonTimeSpanSyncOpMode.Name = "m_radioButtonTimeSpanSyncOpMode";
    this.m_radioButtonTimeSpanSyncOpMode.UseVisualStyleBackColor = true;
    this.m_radioButtonTimeSpanSyncOpMode.CheckedChanged += new EventHandler(this.m_radioButtonTimeSpanSyncOpMode_CheckedChanged);
    componentResourceManager.ApplyResources((object) this.m_radioButtonDefaultOpMode, "m_radioButtonDefaultOpMode");
    this.m_radioButtonDefaultOpMode.Checked = true;
    this.m_radioButtonDefaultOpMode.Name = "m_radioButtonDefaultOpMode";
    this.m_radioButtonDefaultOpMode.TabStop = true;
    this.m_radioButtonDefaultOpMode.UseVisualStyleBackColor = true;
    this.m_radioButtonDefaultOpMode.CheckedChanged += new EventHandler(this.m_radioButtonDefaultOpMode_CheckedChanged);
    componentResourceManager.ApplyResources((object) this.m_buttonCancel, "m_buttonCancel");
    this.m_buttonCancel.Name = "m_buttonCancel";
    this.m_buttonCancel.UseVisualStyleBackColor = true;
    this.m_buttonCancel.Click += new EventHandler(this.m_buttonCancel_Click);
    componentResourceManager.ApplyResources((object) this.m_buttonOk, "m_buttonOk");
    this.m_buttonOk.Name = "m_buttonOk";
    this.m_buttonOk.UseVisualStyleBackColor = true;
    this.m_buttonOk.Click += new EventHandler(this.m_buttonOk_Click);
    componentResourceManager.ApplyResources((object) this.groupBox1, "groupBox1");
    this.groupBox1.Controls.Add((Control) this.m_pictureBoxSimUnit);
    this.groupBox1.Controls.Add((Control) this.m_buttonBrowseSimUnitPath);
    this.groupBox1.Controls.Add((Control) this.m_textBoxSimUnitPath);
    this.groupBox1.Controls.Add((Control) this.m_labelSimUnitPath);
    this.groupBox1.Name = "groupBox1";
    this.groupBox1.TabStop = false;
    componentResourceManager.ApplyResources((object) this.m_pictureBoxSimUnit, "m_pictureBoxSimUnit");
    ((Control) this.m_pictureBoxSimUnit).Name = "m_pictureBoxSimUnit";
    this.m_pictureBoxSimUnit.TabStop = false;
    componentResourceManager.ApplyResources((object) this.m_buttonBrowseSimUnitPath, "m_buttonBrowseSimUnitPath");
    this.m_buttonBrowseSimUnitPath.Name = "m_buttonBrowseSimUnitPath";
    this.m_buttonBrowseSimUnitPath.UseVisualStyleBackColor = true;
    this.m_buttonBrowseSimUnitPath.Click += new EventHandler(this.m_buttonBrowseSimUnitPath_Click);
    componentResourceManager.ApplyResources((object) this.m_textBoxSimUnitPath, "m_textBoxSimUnitPath");
    this.m_textBoxSimUnitPath.Name = "m_textBoxSimUnitPath";
    this.m_textBoxSimUnitPath.ReadOnly = true;
    componentResourceManager.ApplyResources((object) this.m_labelSimUnitPath, "m_labelSimUnitPath");
    this.m_labelSimUnitPath.Name = "m_labelSimUnitPath";
    componentResourceManager.ApplyResources((object) this.m_winModgroupBox, "m_winModgroupBox");
    this.m_winModgroupBox.Controls.Add((Control) this.m_WinModpictureBox);
    this.m_winModgroupBox.Controls.Add((Control) this.m_lableWinModMsUnit);
    this.m_winModgroupBox.Controls.Add((Control) this.m_winMod_TimeOut);
    this.m_winModgroupBox.Controls.Add((Control) this.m_timeOutLable);
    this.m_winModgroupBox.Name = "m_winModgroupBox";
    this.m_winModgroupBox.TabStop = false;
    componentResourceManager.ApplyResources((object) this.m_WinModpictureBox, "m_WinModpictureBox");
    ((Control) this.m_WinModpictureBox).Name = "m_WinModpictureBox";
    this.m_WinModpictureBox.TabStop = false;
    componentResourceManager.ApplyResources((object) this.m_lableWinModMsUnit, "m_lableWinModMsUnit");
    this.m_lableWinModMsUnit.Name = "m_lableWinModMsUnit";
    this.m_winMod_TimeOut.BorderStyle = BorderStyle.Fixed3D;
    componentResourceManager.ApplyResources((object) this.m_winMod_TimeOut, "m_winMod_TimeOut");
    this.m_winMod_TimeOut.LowerBound = 1.0;
    ((Control) this.m_winMod_TimeOut).Name = "m_winMod_TimeOut";
    this.m_winMod_TimeOut.ReadOnly = false;
    this.m_winMod_TimeOut.StepSize = 1.0;
    this.m_winMod_TimeOut.TextAlign = HorizontalAlignment.Left;
    this.m_winMod_TimeOut.ThousandsSeparator = false;
    this.m_winMod_TimeOut.UpperBound = 10000.0;
    this.m_winMod_TimeOut.UseDecimalPlacesFromOption = true;
    this.m_winMod_TimeOut.Value = 1.0;
    this.m_winMod_TimeOut.ValueType = (TxNumericEditValueType) 3;
    componentResourceManager.ApplyResources((object) this.m_timeOutLable, "m_timeOutLable");
    this.m_timeOutLable.Name = "m_timeOutLable";
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleDimensions = new SizeF(6f, 13f);
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Control) this).Controls.Add((Control) this.m_winModgroupBox);
    ((Control) this).Controls.Add((Control) this.groupBox1);
    ((Control) this).Controls.Add((Control) this.m_buttonOk);
    ((Control) this).Controls.Add((Control) this.m_buttonCancel);
    ((Control) this).Controls.Add((Control) this.m_simulationSettingsGroupBox);
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiSimulationSettingsForm);
    ((Form) this).ShowIcon = false;
    ((Form) this).SizeGripStyle = SizeGripStyle.Hide;
    ((Form) this).FormClosing += new FormClosingEventHandler(this.CUiSimulationSettingsForm_FormClosing);
    this.m_simulationSettingsGroupBox.ResumeLayout(false);
    this.m_simulationSettingsGroupBox.PerformLayout();
    this.groupBox1.ResumeLayout(false);
    this.groupBox1.PerformLayout();
    this.m_winModgroupBox.ResumeLayout(false);
    this.m_winModgroupBox.PerformLayout();
    ((Control) this).ResumeLayout(false);
  }
}
